<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



<!DOCTYPE html>
<!--[if IE 6 ]> <html class="ie6 lte_ie6 lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 6 ]> <html class="lte_ie6 lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 7 ]> <html class="lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 8 ]> <html class="lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 9 ]> <html class="lte_ie9"> <![endif]-->
<!--[if (gte IE 10)|!(IE)]><!--><html><!--<![endif]-->
<head>
    <title>新建证照信息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" type="text/css" href="/css/style.css" />
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/news/page.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>

    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript" >
        var MYOA_JS_SERVER = "";
        var MYOA_STATIC_SERVER = "";
    </script>

    <style>

        body{
            font-size: 11px;
            font-family: 微软雅黑;
        }

        .TableBlock .TableData td, .TableBlock td.TableData {
            background: #FFFFFF;
            border-bottom: none;
            border-right: none;
            padding: 3px;
        }
        .big3{
            margin-left: 5px;
            font-family: Microsoft yahei,Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;
            margin-top: -3px;
            margin-right: 40px;
            font-size: 22px;
            color: #494d59;
            font-weight: inherit;
        }


        .btn_ .btn_style {
            background: url("../../img/save.png") no-repeat;
        }
        #rs {
            display: inline-block;
            float: left;
            width: 66px;
            height: 30px;
            text-align: center;
            margin-top: 10px;
            margin-bottom: 20px;
            /* padding-left: 23px; */
            padding-top: 7px;
            cursor: pointer;
            font-size: 14px;
            /*background: url(../../img/publish.png) no-repeat;*/
            margin-left: 40%;
            background-color: #2F8AE3;
            color: #fff;
            border-radius: 5px;
            text-align: center;
        }
        .TableData{
            font-size: 11px;
            color: #2a588c;
            /*   font-weight: bold;*/
        }
        .TableBlock tbody tr{
            height: 52px;
        }
        .TableBlock tbody tr td{
            border: 1px solid #c0c0c0;
        }
        .TableBlock{
            border: 1px #124164 solid;
        }


        .TableBlock tr td:first-of-type,table tr td:nth-child(3){
            text-align: right;
        }
        .div_1{
            margin-left: 20px;
        }
        .newClass{
            position:absolute;
            top:0;
            right:0;
            width: 90px;
            height: 28px;
            background: url(../../img/file/cabinet01.png) no-repeat;
            color: #fff;
            font-size: 11px;
            line-height: 28px;
            margin: 2% 3% 0 0;
            cursor: pointer;
        }
        .bar {
            height: 18px;
            background: green;
        }
    </style>
</head>


<script type="text/javascript">

</script>

<body class="bodycolor" topmargin="5">
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small">
    <tr>
        <td>
            <div class="div_1">
                <img src="/img/commonTheme/${sessionScope.InterfaceModel}/notify_new.png" align="absmiddle"><span class="big3" id="title_info">新建证照信息</span>&nbsp;&nbsp;
            </div>
            <div class="newClass" id="turn" style="display: block;">
                <span style="margin-left: 43px;">
                <%--<img style="margin-right: 4px;margin-left: -11px;margin-bottom: -2px;" src="/img/mywork/newbuildworjk.png" alt="">--%>
                返回
            </span>
                    <%--<span style="margin-left: 30px;">--%>
                <%--<img style="margin-right: 4px;margin-left: -11px;margin-bottom: 4px;" src="../../img/mywork/newbuildworjk.png" alt="">--%>
                <%--返回--%>
            <%--</span>--%>
            </div>
        </td>
    </tr>
</table>
<br>
<form enctype="multipart/form-data" action=""  method="post" id="form1" name="form1" onSubmit="return CheckForm();">
    <table class="TableBlock" width="80%" align="center">

        <tr>
            <td nowrap class="TableData">单位员工：</td>
            <td class="TableData">
                <input type="text" id="userId" name="userId" style="width: 158px;height:28px;" size="12" class="BigStatic" readonly value="">&nbsp;
                <a href="javascript:;" id="departAdd" class="departAdd" ><fmt:message code="global.lang.select" /></a>
            </td>
            <td nowrap class="TableData">证照类型：</td>
            <td class="TableData">
                <select name="licenseType" id="licenseType" style="background: white; width:170px;height: 28px;" title="">
                    <option value=""><fmt:message code="hr.th.PleaseSelect" /></option>
                    <%--<option value="驾驶证">驾驶证</option>--%>
                    <%--<option value="健康证">健康证</option>--%>
                    <%--<option value="暂住证">暂住证</option>--%>
                    <%--<option value="技能证">技能证</option>--%>
                    <%--<option value="其他">其他</option>--%>
                </select>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">证件编号：</td>
            <td class="TableData">
                <input type="text" id="licenseNo" style="width: 158px;height:28px;" name="classcadre" size="12" maxlength="10" class="BigInput" value=""/>
            </td>

            <td nowrap class="TableData">证件名称：</td>
            <td class="TableData">
                <input type="text" id="licenseName" style="width: 158px;height:28px;" name="certifier" size="12" maxlength="10" class="BigInput" value=""/>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">取证日期：</td>
            <td class="TableData">
                <input type="text" id="startTime" style="width: 158px;height:28px;" name="getLicense" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>

            <td nowrap class="TableData">生效日期：</td>
            <td class="TableData">
                <input type="text" id="endTime" style="width: 158px;height:28px;" name="effective" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">状态：</td>
            <td class="TableData">
                <select name="status" id="status" style="background: white; width:170px;height: 28px;" title="">
                    <option value=""><fmt:message code="hr.th.PleaseSelect" /></option>
                    <%--<option value="未生效">未生效</option>--%>
                    <%--<option value="生效中">生效中</option>--%>
                    <%--<option value="已到期">已到期</option>--%>
                </select>
            </td>
            <td nowrap class="TableData">期限限制：</td>
            <td class="TableData radioBox">
                <input type="radio" name="sex" value="否" /> 否  <input type="radio" name="sex" value="是" /> 是
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">发证机构：</td><%--备注--%>
            <td class="TableData" colspan=3>
                <input type="text" id="notifiedBody" style="width: 158px;height:28px;" name="notifiedBody" size="12" maxlength="10" class="BigInput" value=""/>
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">备注：</td><%--备注--%>
            <td class="TableData" colspan=3>
                <textarea name="remark" id="remark" cols="84" rows="3" class="BigInput" value=""></textarea>
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">附件：</td><%--备注--%>
            <td class="TableData" id="files_txt" colspan=3>
                <%--<textarea name="remark" id="remark" cols="84" rows="3" class="BigInput" value=""></textarea>--%>
            </td>
        </tr>
        <tr>
              <td nowrap class="TableData">附件上传：</td>

              <td colspan=3>
                  <%--<div id="query_uploadArr" style="margin-bottom: 5px;"></div>--%>
                  <div style="float: left;margin-right: 10px;"><img style="margin-left: 9px;margin-top: 3px;" src="/img/mg11.png" alt=""/></div>
                  <div style="float: left;">
                      <form id="uploadimgform" target="uploadiframe" action="/upload?module=sdas"
                            enctype="multipart/form-data" method="post" style="position: relative">
                          <input type="file" name="file" multiple="multiple" id="uploadinputimg" class="w-icon5"
                                 style="position: absolute;opacity: 0;width: 70px;z-index: -1;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">
                          <a id="uploadimg" style="font-size:16px; cursor: pointer;"><fmt:message code="notice.th.addfile"/></a>

                      </form>
                  </div>
                      <div id="progress" style="width: 200px;float: left;margin-left: 10px;margin-top: 2px;">
                          <div class="bar" style="width: 0%;"></div>
                      </div>
                      <div class="barText" style="float: left;margin-left: 10px;"></div>
              </td>
          </tr>

        <tr align="center" class="TableControl">
            <td colspan=4 nowrap>
                <div id="rs" type="save" class="btn_style btn_ok"><fmt:message code="global.lang.save" /></div><%--保存--%>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">
    var type = $.GetRequest().type;
    var userId= decodeURI($.GetRequest().userId);
    $("#turn").click(function () {
        if(type!=undefined){
            window.location.href = "/hr/manage/photoManage?type=1&userId="+userId;
        }else{
            window.location.href = "/hr/manage/photoManage";
        }

    })

    var user_id;
    var depart_id;
    //时间控件调用
    var start = {
        format: 'YYYY-MM-DD',
        /* min: laydate.now(), //设定最小日期为当前日期*/
        /* max: '2099-06-16 23:59:59', //最大日期*/
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        format: 'YYYY-MM-DD',
        /*min: laydate.now(),*/
        /*max: '2099-06-16 23:59:59',*/
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };

    function selectNumber(name,val){
        var numbers = $("select[name="+name+"]").find("option"); //获取select下拉框的所有值
        for (var j = 1; j < numbers.length; j++) {
            if ($(numbers[j]).val() == val) {
                $(numbers[j]).attr("selected", "selected");
            }
        }
    };

    $(function () {
        $.ajax({  //填充状态下拉框
            type:'get',
            url:'/hr/manage/getHrCodes',
            dataType:'json',
            data:{type:'edu'},
            async:false,
            success:function(res){
                if(res.flag) {
                    var lists = res.data;
                    var render = [];
                    render.push("<option value=''><fmt:message code='hr.th.PleaseSelect' /></option>")
                    for(var i=0;i<lists.length;i++){
                        render.push("<option value=\""+lists[i].codeNo+"\">"+lists[i].codeName+"</option>");
                    }
                    $("#status").html(render.join(""));
                }

            }
        })
        $.ajax({  //填充证照类型
            type:'get',
            url:'/hr/manage/getHrCodes',
            dataType:'json',
            data:{type:'degree'},
            async:false,
            success:function(res){
                if(res.flag) {
                    var lists = res.data;
                    var render = [];
                    render.push("<option value=''><fmt:message code='hr.th.PleaseSelect' /></option>")
                    for(var i=0;i<lists.length;i++){
                        render.push("<option value=\""+lists[i].codeNo+"\">"+lists[i].codeName+"</option>");
                    }
                    $("#licenseType").html(render.join(""));
                }

            }
        })
    });

    var typeHr=getQueryString('typeHr');
    $(function () {
        if(typeHr == '1'){
            $('#turn').hide();
        }else{
            $('#turn').show();
        }
        var id=$.getQueryString('licenseId');
        if(id){
            $(document).attr('title','修改证照信息');
            $('#title_info').html('修改证照信息');
            $.ajax({
                url: "/hr/manage/selectHrphotos",
                type: "get",
                data: {
                    'licenseId': id
                },
                dataType: 'json',
                success: function (obj) {
                    var data=obj.obj[0];
                    console.log(data);
                    var arr = data.attachmentList;
                    var str1=""
                    if (data.attachmentList != '') {
                        for (var i = 0; i < (arr.length); i++) {
                            str1+='<div class="dech" deUrl="'+encodeURI(arr[i].attUrl)+'" style="display:block;"><a class="ATTACH_a" NAME="'+arr[i].attachName+'*" href="<%=basePath %>download?'+encodeURI(arr[i].attUrl)+'">'+arr[i].attachName+'</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" NAME="'+arr[i].attachName+'*"  class="inHidden" value="'+arr[i].aid+'@'+arr[i].ym+'_'+arr[i].attachId+',"></div>';
                        }
                        $('#files_txt').append(str1);
                    };

                    $('#userId').attr('user_id',data.userId);
//                    $('#licenseType').find('option[value='+data.licenseType+']').attr('selected','selected');
                    $('#licenseType').val(data.licenseType);
                    $('#licenseNo').val(data.licenseNo);
                    $('#licenseName').val(data.licenseName);
                    $('#startTime').val(data.getLicenseDate);
                    $('#endTime').val(data.effectiveDate);
                    $('.radioBox').find('input[value='+data.expirationPeriod+']').attr('checked', 'true');
                    $('#notifiedBody').val(data.notifiedBody);
                   // console.log(data.status);
//                    selectNumber('status',data.status)
//                    selectNumber('licenseType',data.licenseType)
                    $('#status').find('option[value='+data.status+']').attr('selected','selected');
                    $('#addTime').html(data.addTime);
                    $('#lastUpdateTime').html(data.lastUpdateTime);
                    $('#remark').html(data.remark);
                    $('#userId').val(data.staffName);


                }
            });

            $('#rs').attr('type','edit')
        }else{
            if(type!=undefined){
                $('#userId').val(parent.userName+',');
                $('#userId').attr('user_id',userId+',');
                $('#userId').attr('dataId',userId+',');
                $('#userId').attr('userName',parent.userName+',');
            }
        }
        // 获取负责人
        $('.userAdd').click(function(){
            user_id="chargePerson";
            $.popWindow("/common/selectUser?0");
        });

        //选择部门
        $('#departAdd').click(function(){
            user_id="userId";
            $.popWindow("/common/selectUser?0");
        })
        //获取审批人
        $('.userAdd_1').click(function(){
            user_id="assessingOfficer";
            $.popWindow("/common/selectUser?0");
        });
        //培训部门
        $('.orgDepartAdd').click(function(){
            dept_id="joinDept";
            $.popWindow("/common/selectDept");
        });
        //清空
        $('.orgDepartClear').click(function(){
            $('#joinDept').attr("dataid","");
            $('#joinDept').attr("depart_id","");
            $('#joinDept').attr("deptname","");
            $('#joinDept').val("");
        })
        //培训人员
        $('.orgUserAdd').click(function(){
            user_id="joinPerson";
            $.popWindow("/common/selectUser");
        });
        // 清空
        $('.orgUserClear').click(function(){
            $('#joinPerson').attr("dataid","");
            $('#joinPerson').attr("user_id","");
            $('#joinPerson').attr("userprivname","");
            $('#joinPerson').attr("username","");
            $('#joinPerson').val("");
        });

        function CheckForm(){
            if($('#planNo').val()==''){
                layer.msg('<fmt:message  code="event.th.PlanNull"/>',{icon:2});
                return false;
            }
            if($('#planName').val()==''){
                layer.msg('<fmt:message  code="event.th.PlanEmpty"/>',{icon:2});
                return false;
            }
            if($('#assessingOfficer').val()==''){ //审批人不能为空
                layer.msg('<fmt:message  code="withdraw.th.shenpi"/>',{icon:2});
                return false;
            }
            return true;
        }

        $('#uploadimg').click(function(){
            me =this;
            $('#form1').attr('action','/upload?module=sdas')
            $('#uploadinputimg').click()
        })

        $('#uploadinputimg').fileupload({
            dataType:'json',
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .bar').css(
                    'width',
                    progress + '%'
                );
                $('.barText').html(progress + '%');
                if(progress >= 100){  //判断滚动条到100%清除定时器
                    timer=setTimeout(function () {
                        $('#progress .bar').css(
                            'width',
                            0 + '%'
                        );
                        $('.barText').html('');
                    },2000);

                }
            },
            done: function (e, data) {
                if(data.result.obj != ''){
                    var data = data.result.obj;
                    var str = '';
                    var str1 = '';
                    for (var i = 0; i < data.length; i++) {
                        str+='<div class="dech" deUrl="'+encodeURI(data[i].attUrl)+'" style="display:block;"><a class="ATTACH_a" NAME="'+data[i].attachName+'*" href="<%=basePath %>download?'+encodeURI(data[i].attUrl)+'">'+data[i].attachName+'</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" NAME="'+data[i].attachName+'*"  class="inHidden" value="'+data[i].aid+'@'+data[i].ym+'_'+data[i].attachId+',"></div>';
                    }
                    $('#files_txt').append(str);
                    $('#query_uploadArr').append(str);
                }else{
                    //alert('添加附件大小不能为空!');
                    layer.alert('添加附件大小不能为空!',{},function(){
                        layer.closeAll();
                    });
                }
            }
        });

        $('#files_txt').on('click','.deImgs',function(){

           var attachId='';
            var attachName='';
          for(var i=0;i<$('#files_txt .inHidden').length;i++){
               attachId+=$('#files_txt .inHidden').eq(i).val();
                attachName+=$('#files_txt a').eq(i).attr('NAME');
          }

            var data=$(this).parents('.dech').attr('deUrl');
            var dome=$(this).parents('.dech');
            console.log(dome);
            deleteChatment(data,dome);
        })

        //删除附件
        function deleteChatment(data,element){

            layer.confirm('<fmt:message code="menuSSetting.th.isdeleteMenu" />？', {/*确定要删除吗*/
                btn: ['<fmt:message code="global.lang.ok" />','<fmt:message code="depatement.th.quxiao" />'], //按钮 /* 确定  取消*/
                title:'<fmt:message code="notice.th.DeleteAttachment" />'/*删除附件*/
            }, function(){
                //确定删除，调接口
                $.ajax({
                    type:'get',
                    url:'/delete',
                    dataType:'json',
                    data:data,
                    success:function(res){

                        if(res.flag == true){
                            layer.msg('<fmt:message code="workflow.th.delsucess" />', { icon:6});/*删除成功*/
                            element.remove();
                        }else{
                            layer.msg('<fmt:message code="lang.th.deleSucess" />', { icon:6});/*删除失败*/
                        }
                    }
                });

            }, function(){
                layer.closeAll();
            });
        }

        // 提交表单
        $("#rs").click(function(){
            $('#form1').attr('action','')
            var fileId=''
            var fileName=''
            if(CheckForm()) {
                for(var i=0;i<$('.inHidden').length;i++){
                    fileId += $('.inHidden').eq(i).val();
                    fileName += $('.inHidden').eq(i).attr('name');
                }
                var data = {
//                    assessingStatus:0,
                    "attachmentId":fileId,
                    "attachmentName":fileName,
                    staffName: $('#userId').attr('user_id'),
                    licenseType: $('#licenseType').val(),
                    licenseNo: $('#licenseNo').val(),
                    licenseName: $('#licenseName').val(),
                    getLicense:$('#startTime').val(),
                    effective:$('#endTime').val(),
                    status: $('#status').val(),
                    expirationPeriod: $("input[name='sex']:checked").val(),
                    remark: $('#remark').val(),
                    notifiedBody: $('#notifiedBody').val()
                }

                var tp = $('#rs').attr('type')
                if(tp == 'save') {
                    $.ajax({
                        type: 'post',
                        url: '/hr/manage/addHrphotos',
                        dataType: 'json',
                        data: data,
                        success: function (rsp) {
                            if (rsp.flag == true) {
                                layer.msg('<fmt:message code="url.th.addSuccess" />', {icon: 1},function () {
                                    if(typeHr == '1'){
                                        window.close();
                                        window.opener.zhengzhaoData();
                                    }else {
                                        /*添加成功*/
                                        if(type!=undefined){
                                            window.location.href='/hr/manage/photoManage?type=1&userId='+userId
                                        }else{
                                            parent.location.href = '/hr/manage/staff_license';
                                        }

                                    }
                                });
                            } else {
                                layer.msg('<fmt:message code="hr.th.AddFailed" />', {icon: 2});
                                /*添加失败*/
                            }
                        }
                    })
                } else {
                    var id=$.getQueryString('licenseId');
                    $.ajax({
                        type: 'post',
                        url: '/hr/manage/upHrphotos',
                        dataType: 'json',
                        data: {
                            assessingStatus:0,
                            "attachmentId":fileId,
                            "attachmentName":fileName,
                            staffName: $('#userId').attr('user_id'),
                            licenseType: $('#licenseType').val(),
                            licenseNo: $('#licenseNo').val(),
                            licenseName: $('#licenseName').val(),
                            getLicense:$('#startTime').val(),
                            effective:$('#endTime').val(),
                            status: $('#status').val(),
                            expirationPeriod: $("input[name='sex']:checked").val(),
                            remark: $('#remark').val(),
                            notifiedBody: $('#notifiedBody').val(),
                            licenseId:id

                        },
                        success: function (rsp) {
                            if (rsp.flag == true) {
                                layer.msg('修改成功', {icon: 1},function () {
                                    if(typeHr == '1'){
                                        window.close();
                                        window.opener.zhengzhaoData();
                                    }else {
                                        /*添加成功*/
                                        if(type!=undefined){
                                            window.location.href='/hr/manage/photoManage?type=1&userId='+userId
                                        }else{
                                            parent.location.href = '/hr/manage/staff_license';
                                        }
                                    }
                                });
                            } else {
                                layer.msg('修改失败', {icon: 2});
                                /*添加失败*/
                            }
                        }
                    })
                }

            }
        });

    });
    //获取url参数
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return r[2];
        return '';
    }
</script>
</body>
</html>

